package com.itheima.controller;

import com.itheima.common.entity.Result;
import com.itheima.common.utils.POIUtils;
import com.itheima.pojo.OrderSetting;
import com.itheima.pojo.OrderSettingDTO;
import com.itheima.pojo.OrderSettingUploadDTO;
import com.itheima.service.OrederSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;

@Slf4j
@RestController
@RequestMapping("/ordersetting")
@Api(tags = "预约设置相关接口")
public class OrderSettingController {

    @Autowired
    private OrederSettingService orederSettingService;

    /**
     * 模板下载
     * @param filename
     * @return
     */
    @GetMapping("/download")
    @ApiOperation("模板下载")
    public Result download (@RequestParam String filename) {
        orederSettingService.download(filename);
        return Result.success();
    }

    /**
     * 根据日期修改可预约人数
     * @param orderSettingDTO
     * @return
     */
    @PutMapping("/editNumberByOrderDate")
    @ApiOperation("根据日期修改可预约人数")
    public Result edit (@RequestBody OrderSettingDTO orderSettingDTO) {
        log.info("根据日期修改可预约人数:{}",orderSettingDTO);
        orederSettingService.updateByDate(orderSettingDTO);
        return Result.success();
    }

    /**
     * 根据日期获取对应数据
     * @param month
     * @return
     */
    @GetMapping("getOrderSettingByMonth")
    @ApiOperation("根据日期获取对应数据")
    public Result<OrderSetting> list (@DateTimeFormat(pattern = "yyyy-MM") Date month) {
        log.info("根据日期获取对应数据:{}",month);
        OrderSetting orderSetting = orederSettingService.getByMonth(month);
        return Result.success(orderSetting);
    }

    /**
     * 读取文件
     * @param upload
     * @return
     */
    @PostMapping("/upload")
    @ApiOperation("读取文件")
    public Result upload (@RequestBody OrderSettingUploadDTO upload) {
        orederSettingService.upload(upload);
        return Result.success();
    }













}
